home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************\
-
- File: ls meat.c
-
- Purpose: This module handles all the blood and guts of Lose Your Marbles!
- play: what constitutes a valid move, etc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program in a file named "GNU General Public License".
- If not, write to the Free Software Foundation, 675 Mass Ave,
- Cambridge, MA 02139, USA.
-
- \**********************************************************************/
-
- #include "ls meat.h"
- #include "environment.h"
- #include "program globals.h"
-
- Boolean DeleteOneMove(Point theMove)
- {
- short i, j;
-
- for (i=0; i<gNumMoves; i++)
- {
- if ((gMoves[i].h==theMove.h) && (gMoves[i].v==theMove.v))
- {
- for (j=i; j<gNumMoves-1; j++)
- {
- gMoves[j].h=gMoves[j+1].h;
- gMoves[j].v=gMoves[j+1].v;
- }
-
- gNumMoves--;
-
- return TRUE;
- }
- }
-
- return FALSE;
- }
-
- Boolean AddOneMove(Point theMove)
- {
- if (gNumMoves==gNumRows*gNumColumns)
- return FALSE;
-
- gMoves[gNumMoves].h=theMove.h;
- gMoves[gNumMoves].v=theMove.v;
- gNumMoves++;
-
- return TRUE;
- }
-
- Boolean UndoOneMove(WindowDataHandle theData)
- {
- Point lastMove;
-
- if (gNumMoves==0)
- return FALSE;
-
- lastMove=gMoves[--gNumMoves];
- FramePosition(gCurrentRow, gCurrentColumn, FALSE);
- gCurrentRow=lastMove.v;
- gCurrentColumn=lastMove.h;
- FramePosition(gCurrentRow, gCurrentColumn, TRUE);
-
- if (Board[gCurrentRow][gCurrentColumn]==0)
- return FALSE;
-
- Board[gCurrentRow][gCurrentColumn]=0;
- DrawOnePosition(gCurrentRow, gCurrentColumn, Board[gCurrentRow][gCurrentColumn], FALSE);
-
- (**theData).offscreenNeedsUpdate=TRUE;
-
- return TRUE;
- }
-
-
- void FramePosition(short theRow, short theColumn, Boolean isHighlighted)
- {
- Rect theRect;
-
- theRect.left=theColumn*38+2;
- theRect.right=theRect.left+36;
- theRect.top=theRow*38+2;
- theRect.bottom=theRect.top+36;
- InsetRect(&theRect, -1, -1);
- if (!isHighlighted)
- ForeColor(whiteColor);
- FrameRect(&theRect);
- ForeColor(blackColor);
- }
-
- void DrawOnePosition(short theRow, short theColumn, short theValue, Boolean isHighlighted)
- {
- Rect tempRect;
-
- tempRect.top=theRow*38+2;
- tempRect.bottom=tempRect.top+36;
- tempRect.left=theColumn*38+2;
- tempRect.right=tempRect.left+36;
- InsetRect(&tempRect, 2, 2);
- if (theValue==0)
- {
- EraseRect(&tempRect);
- }
- else
- {
- if (gHasColorQD)
- PlotCIcon(&tempRect, gTheCIcon[theValue-1]);
- else
- PlotIcon(&tempRect, gTheIcon[theValue-1]);
- }
- if (isHighlighted)
- {
- InvertRect(&tempRect);
- }
- }
-